package com.ax.service.imple;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;

import com.ax.pojo.TabSysUsers;
import com.ax.service.TabSysUsersService;
import com.ax.utils.BaseDaoSupport;
import com.ax.utils.PageInfo;

@Service("tabSysUsersService")
public class TabSysUsersServiceImple implements TabSysUsersService {

	
	private BaseDaoSupport<TabSysUsers> dao;
	
	@Resource(name="sessionFactory")
	public void setSessionFactort(SessionFactory sessionFactory){
		 dao=new BaseDaoSupport<TabSysUsers>();
		 dao.setSessionFactory(sessionFactory);
	}
	public TabSysUsers getTabSysUsers(String uname) {
		// TODO Auto-generated method stub
		return (TabSysUsers)dao.executeHQLForObject("from TabSysUsers s where s.uname=?",uname);
	}
	public PageInfo findPageInfo(int currentPageSize, String code ) {
		PageInfo pageInfo=new PageInfo();
		pageInfo.setData(dao.getPaginationData(code+" order by po.uid desc", currentPageSize, pageInfo.getPageSize(), TabSysUsers.class,null));
		pageInfo.setTotalCount(((Long)dao.getDataCount(TabSysUsers.class,code)).intValue());
		pageInfo.setCurPage(currentPageSize);
		return pageInfo;
	}
	public boolean updateSysUsers(TabSysUsers sysUsers) {
		boolean flag=true;
		 try {
			dao.update(sysUsers);
		} catch (Exception e) {
			// TODO: handle exception
			flag=false;
		}
		return flag;
	}
	public boolean saveSysUsers(TabSysUsers sysUsers) {
		boolean flag=true;
		 try {
			dao.save(sysUsers);
		} catch (Exception e) {
			// TODO: handle exception
			flag=false;
		}
		return flag;
	}

}
